package com.youku
{
   import flash.events.EventDispatcher;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.interfaces.IPlayerData;
   import com.youku.interfaces.IRootGetData;
   import flash.utils.Dictionary;
   import flash.events.IEventDispatcher;
   import com.youku.events.BasePlayerEvent;
   import com.youku.events.CoreEvent;
   import com.youku.events.PluginEvent;
   import com.youku.events.ConductorEvent;
   import com.youku.events.CommonPlayerEvent;
   import com.youku.interfaces.IExternalProxy;
   import com.youku.interfaces.IFSOProxy;
   import com.youku.interfaces.IPartnerData;
   import com.youku.interfaces.IApiData;
   import com.youku.data.PlayerData;
   import com.youku.data.RootGetData;
   
   public class PlayerProxy extends EventDispatcher implements IPlayerProxy
   {
      
      public function PlayerProxy() {
         super();
         this._playerData = new PlayerData();
         this._rootGetData = new RootGetData();
      }
      
      private var _playerData:IPlayerData;
      
      private var _rootGetData:IRootGetData;
      
      public function addEventListeners(param1:Dictionary) : void {
         var _loc2_:String = null;
         var _loc3_:IEventDispatcher = null;
         var _loc4_:Array = null;
         var _loc5_:String = null;
         for(_loc2_ in param1)
         {
            _loc3_ = param1[_loc2_].dispatcher;
            _loc4_ = param1[_loc2_].events;
            for each(_loc5_ in _loc4_)
            {
               if(!_loc3_.hasEventListener(_loc5_))
               {
                  _loc3_.addEventListener(_loc5_,this.TransmitEvent);
               }
            }
         }
      }
      
      public function removeEventListeners(param1:Dictionary) : void {
         var _loc2_:String = null;
         var _loc3_:IEventDispatcher = null;
         var _loc4_:Array = null;
         var _loc5_:String = null;
         for(_loc2_ in param1)
         {
            _loc3_ = param1[_loc2_].dispatcher;
            _loc4_ = param1[_loc2_].events;
            for each(_loc5_ in _loc4_)
            {
               if(_loc3_.hasEventListener(_loc5_))
               {
                  _loc3_.removeEventListener(_loc5_,this.TransmitEvent);
               }
            }
         }
      }
      
      private function TransmitEvent(param1:BasePlayerEvent) : void {
         if(param1 is CoreEvent)
         {
            dispatchEvent(new CoreEvent(param1.type,param1.data));
         }
         else if(param1 is PluginEvent)
         {
            dispatchEvent(new PluginEvent(param1.type,param1.data));
         }
         else if(param1 is ConductorEvent)
         {
            dispatchEvent(new ConductorEvent(param1.type,param1.data));
         }
         else if(param1 is CommonPlayerEvent)
         {
            dispatchEvent(new CommonPlayerEvent(param1.type,param1.data));
         }
         else
         {
            dispatchEvent(new BasePlayerEvent(param1.type,param1.data));
         }
         
         
         
      }
      
      public function get externalProxy() : IExternalProxy {
         return GlobalService.getService(GlobalServiceKeys.EXTERNALINTERFACE_PROXY) as IExternalProxy;
      }
      
      public function get fsoProxy() : IFSOProxy {
         return GlobalService.getService(GlobalServiceKeys.FSO_PROXY) as IFSOProxy;
      }
      
      public function get playerData() : IPlayerData {
         return this._playerData;
      }
      
      public function get partnerData() : IPartnerData {
         return PlayerConfig.partnerData;
      }
      
      public function get apiData() : IApiData {
         return PlayerConfig.apiData;
      }
      
      public function get rootGetData() : IRootGetData {
         return this._rootGetData;
      }
   }
}
